home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr11 / pctv4n2.zip / GRWORLD.PAS < prev    next >
Pascal/Delphi Source File  |  1993-06-09  |  26KB  |  720 lines

  1. {===============================================================
  2.   GrWorld - TP Unit for containing WCoordPlane class definition.
  3.  
  4.   Copyright (C) 1992 by Raymond Konopka, Jr.
  5.  ===============================================================}
  6.  
  7. unit GrWorld;
  8.  
  9. interface  {=== GrWorld Unit ===}
  10.  
  11. uses
  12.     Graph;
  13.  
  14. const
  15.     MAX_POINTS = 5000;          { Max of 5000 points in Polygon }
  16.  
  17. type                            { Types needed for WCP Polygons }
  18.     RealPointType = record
  19.         x, y : Real;
  20.     end;
  21.     PPointArray = ^PointArray; { PointType defined in GRAPH.TPU }
  22.     PointArray = Array[ 1..MAX_POINTS ] of PointType;
  23.     PRealPointArray = ^RealPointArray;
  24.     RealPointArray = Array[ 1..MAX_POINTS ] of RealPointType;
  25.  
  26. type
  27.     PWCoordPlane = ^WCoordPlane;
  28.     WCoordPlane = object         { WCoordPlane class definition }
  29.         {= Data =}
  30.         wxUL, wyUL, wxLR, wyLR : Real;        { Limits of World }
  31.         vpMaxX, vpMaxY : Integer;      { Max x & y values in VP }
  32.         flipX, flipY : Boolean;   { T if Axis diff dir than ACP }
  33.         xScale, yScale : Real;            { Scale of x & y axes }
  34.         currentPtrPos : PointType;   { Current Pointer Position }
  35.         viewPort : ViewPortType;    { Location of WCP on Screen }
  36.         textSettings : TextSettingsType;
  37.         lineSettings : LineSettingsType;
  38.         fillSettings : FillSettingsType;
  39.         fillPattern : FillPatternType;
  40.         writeMode : Integer;
  41.         currentColor : Word;
  42.  
  43.         {= Methods =}
  44.         constructor Init( wULx, wULy, wLRx, wLRy : Real;
  45.                           vULx, vULy, vLRx, vLRy : Integer );
  46.         {= Internal Methods - Not Inforced =}
  47.         procedure Convert( wx, wy : Real; var x, y : Integer );
  48.         procedure ConvertRel( wdx, wdy: Real; var dx, dy: Integer );
  49.         procedure ConvertRadii( wxRadius, wyRadius : Real;
  50.                                 var xRadius, yRadius : Word );
  51.         procedure ActivateViewPort; virtual;
  52.         procedure LocateCurrentPtr; virtual;
  53.         {= Drawing Methods =}
  54.         procedure Arc( wx, wy : Real; stAngle, endAngle : Word;
  55.                        wRadius : Real ); virtual;
  56.         procedure Bar( wx1, wy1, wx2, wy2 : Real ); virtual;
  57.         procedure Bar3D( wx1, wy1, wx2, wy2 : Real; depth : Word;
  58.                          top : Boolean ); virtual;
  59.         procedure Circle( wx, wy, wRadius : Real ); virtual;
  60.         procedure ClearWorld; virtual;
  61.         procedure DrawPoly( numPoints : Word;
  62.                             var polyPoints ); virtual;
  63.         procedure Ellipse( wx, wy : Real; stAngle, endAngle : Word;
  64.                            wxRadius, wyRadius : Real ); virtual;
  65.         procedure FillEllipse( wx, wy,
  66.                                wxRadius, wyRadius : Real ); virtual;
  67.         procedure FillPoly( numPoints : Word;
  68.                             var polyPoints ); virtual;
  69.         procedure FloodFill( wx, wy : Real; border: Word ); virtual;
  70.         procedure GetImage( wx1, wy1, wx2, wy2 : Real;
  71.                             var bitMap ); virtual;
  72.         function GetPixel( wx, wy : Real ): Word; virtual;
  73.         function ImageSize( wx1, wy1, wx2, wy2:Real ):Word; virtual;
  74.         procedure Line( wx1, wy1, wx2, wy2 : Real ); virtual;
  75.         procedure LineRel( wdx, wdy : Real ); virtual;
  76.         procedure LineTo( wx, wy : Real ); virtual;
  77.         procedure MoveRel( wdx, wdy : Real ); virtual;
  78.         procedure MoveTo( wx, wy : Real ); virtual;
  79.         procedure OutTextXY( wx, wy : Real;
  80.                              message : String ); virtual;
  81.         procedure PieSlice( wx, wy : Real;
  82.                             stAngle, endAngle : Word;
  83.                             wRadius : Real ); virtual;
  84.         procedure PutImage( wx, wy : Real; var bitMap;
  85.                             bitBlt : Word ); virtual;
  86.         procedure PutPixel( wx, wy : Real; color : Word ); virtual;
  87.         procedure Rectangle( wx1, wy1, wx2, wy2 : Real ); virtual;
  88.         procedure Sector( wx, wy : Real; stAngle, endAngle : Word;
  89.                           wxRadius, wyRadius : Real ); virtual;
  90.         procedure SetColor( color : Word ); virtual;
  91.         procedure SetFillPattern( pattern : FillPatternType;
  92.                                   color : Word ); virtual;
  93.         procedure SetFillStyle( pattern, color : Word ); virtual;
  94.         procedure SetLineStyle( lineStyle, pattern,
  95.                                 thickness : Word ); virtual;
  96.         procedure SetTextJustify( horiz, vert : Word ); virtual;
  97.         procedure SetTextStyle( font, direction,
  98.                                 charSize : Word ); virtual;
  99.         procedure SetWriteMode( mode : Integer ); virtual;
  100.         procedure Axes( wxOrigin, wyOrigin, xDelta, yDelta : Real;
  101.                         xAxis, yAxis, precision : Integer;
  102.                         arrows : Boolean;
  103.                         color : Word ); virtual;
  104.     end; {= WCoordPlane Class Definition =}
  105.  
  106. implementation {=== GrWorld Unit ===}
  107.  
  108. {== WCoordPlane Methods ==}
  109.  
  110. {= Init - This constructor is used to create a WCP.           =}
  111. {=        wULx, wULy, wLRx, wLRy - specify limits of WCP      =}
  112. {=        vULx, vULy, vLRx, vLRy - specify location on screen =}
  113. constructor WCoordPlane.Init( wULx, wULy, wLRx, wLRy : Real;
  114.                               vULx, vULy, vLRx, vLRy : Integer );
  115. var
  116.     temp : Real;
  117. begin
  118.     Graph.SetViewPort( vULx, vULy, vLRx, vLRy, ClipOn );
  119.     Graph.GetViewSettings( viewPort );
  120.     Graph.GetFillSettings( fillSettings );
  121.     Graph.GetLineSettings( lineSettings );
  122.     Graph.GetFillPattern( fillPattern );
  123.     Graph.GetTextSettings( textSettings );
  124.  
  125.     with viewPort do
  126.     begin
  127.         vpMaxX := x2 - x1;        { Calculate Max X value in VP }
  128.         vpMaxY := y2 - y1;        { Calculate Max Y value in VP }
  129.     end;
  130.  
  131.     if wULx > wLRx then
  132.     begin                            { Does x axis inc to left? }
  133.         flipX := TRUE;                 { If so then flip values }
  134.         temp := wULx;
  135.         wULx := wLRx;
  136.         wLRx := temp;
  137.     end
  138.     else
  139.         flipX := FALSE;
  140.  
  141.     if wULy > wLRy then
  142.     begin                         { Does y axis inc going down? }
  143.         flipY := TRUE;              { & y values in upper right }
  144.         temp := wULy;                
  145.         wULy := wLRy;
  146.         wLRy := temp;
  147.     end
  148.     else
  149.         flipY := FALSE;
  150.  
  151.     { Calculate logical distance between adjacent pixels }
  152.     xScale := vpMaxX / Abs( wLRx - wULx );
  153.     yScale := vpMaxY / Abs( wLRy - wULy );
  154.  
  155.     wxUL := wULx;              { Save the limits of the WCP for }
  156.     wyUL := wULy;              { use in Convert and Axes methods}
  157.     wxLR := wLRx;           
  158.     wyLR := wLRy;
  159.  
  160.     currentPtrPos.x := 0;        { CP starts in UL corner of VP }
  161.     currentPtrPos.y := 0;
  162.     writeMode := CopyPut;                { Default Writing Mode }
  163.     currentColor := GetColor;      { Set color to Current Value }
  164. end; {= Init =}
  165.  
  166. {= Convert - Translates WCP point to ACP pixel =}
  167. procedure WCoordPlane.Convert( wx, wy : Real; var x, y: Integer );
  168. begin
  169.     if flipX then  { If flip then base trans on LR point of WCP }
  170.         x := Trunc( ( wxLR - wx ) * xScale )
  171.     else
  172.         x := Trunc( ( wx - wxUL ) * xScale );
  173.  
  174.     if flipY then  { If flip then base trans on LR point of WCP }
  175.         y := Trunc( ( wyLR - wy ) * yScale )
  176.     else
  177.         y := Trunc( ( wy - wyUL ) * yScale );
  178. end; {= Convert =}
  179.  
  180. {= ConvertRel - Translate delta in WCP to delta in ACP. =}
  181. procedure WCoordPlane.ConvertRel( wdx, wdy : Real;
  182.                                   var dx, dy : Integer );
  183. var
  184.     xNeg, yNeg : Boolean;
  185.     xOrigin, yOrigin : Integer;
  186. begin
  187.     Convert( 0, 0, xOrigin, yOrigin );{ Get VP coords of origin }
  188.     Convert( wdx, wdy, dx, dy );  { Treat (wdx, wdy) as a point }
  189.     dx := dx - xOrigin;                   { Translate to Origin }
  190.     dy := dy - yOrigin;                   { Translate to Origin }
  191.  
  192.     if flipX and ( wdx >= 0 ) then
  193.         xNeg := TRUE
  194.     else
  195.         xNeg := FALSE;
  196.  
  197.     if not flipY and ( wdy >= 0 ) then
  198.         yNeg := TRUE
  199.     else
  200.         yNeg := FALSE;
  201.  
  202.     if xNeg then
  203.         dx := -dx;               { Adjust for correct direction }
  204.     if yNeg then
  205.         dy := -dy;
  206. end; {= ConvertRel =}
  207.  
  208. {= ConvertRadii - Translate radius in WCP to radius in VCP.    =}
  209. procedure WCoordPlane.ConvertRadii( wxRadius, wyRadius : Real;
  210.                                     var xRadius, yRadius: Word );
  211. var
  212.     xOrigin, yOrigin, xRad, yRad : Integer;
  213. begin
  214.     Convert( 0, 0, xOrigin, yOrigin );{ Get VP coords of origin }
  215.     Convert( wxRadius, wyRadius, xRad, yRad );
  216.     xRadius := Abs( xRad - xOrigin );     { Translate to Origin }
  217.     yRadius := Abs( yRad - yOrigin );     { Translate to Origin }
  218. end; {= ConvertRadii =}
  219.  
  220. {= ActivateViewPort - Reestablish saved settings of VP.  Req'd =}
  221. {=                    when multiple WCPs are being used.       =}
  222. procedure WCoordPlane.ActivateViewPort;
  223. begin
  224.     with viewport do
  225.         SetViewPort( x1, y1, x2, y2, clip );
  226.     Graph.MoveTo( currentPtrPos.x, currentPtrPos.y );
  227.  
  228.     with fillSettings do
  229.     begin
  230.         Graph.SetFillStyle( pattern, color );
  231.         if pattern = UserFill then
  232.             Graph.SetFillPattern( fillPattern, color );
  233.     end;
  234.     with lineSettings do
  235.         Graph.SetLineStyle( lineStyle, pattern, thickness );
  236.     with textSettings do
  237.     begin
  238.         Graph.SetTextJustify( horiz, vert );
  239.         Graph.SetTextStyle( font, direction, charSize );
  240.     end;
  241.     Graph.SetWriteMode( writeMode );
  242.     Graph.SetColor( currentColor );
  243. end;
  244.  
  245. {= LocateCurrentPtr - Records the location of current pointer =}
  246. procedure WCoordPlane.LocateCurrentPtr;
  247. begin
  248.     currentPtrPos.x := GetX;
  249.     currentPtrPos.y := GetY;
  250. end;
  251.  
  252. {= Arc - WCP equivalent to BGI Arc procedure =}
  253. procedure WCoordPlane.Arc( wx, wy : Real; stAngle, endAngle: Word;
  254.                            wRadius : Real );
  255. var
  256.     x, y : Integer;
  257. begin
  258.     Ellipse( wx, wy, stAngle, endAngle, wRadius, wRadius );
  259. end; {= Arc =}
  260.  
  261. {= Bar - WCP equivalent to BGI Bar procedure =}
  262. procedure WCoordPlane.Bar( wx1, wy1, wx2, wy2 : Real );
  263. var 
  264.     x1, y1, x2, y2 : Integer;
  265. begin
  266.     ActivateViewPort;
  267.     Convert( wx1, wy1, x1, y1 );
  268.     Convert( wx2, wy2, x2, y2 );
  269.     Graph.Bar( x1, y1, x2, y2 );
  270. end; {= Bar =}
  271.  
  272. {= Bar3D - WCP equivalent to BGI Bar3D procedure =}
  273. procedure WCoordPlane.Bar3D( wx1, wy1, wx2, wy2 : Real;
  274.                              depth : Word; top : Boolean );
  275. var
  276.     x1, y1, x2, y2 : Integer;
  277. begin
  278.     ActivateViewPort;
  279.     Convert( wx1, wy1, x1, y1 );
  280.     Convert( wx2, wy2, x2, y2 );
  281.     Graph.Bar3D( x1, y1, x2, y2, depth, top );
  282. end; {= Bar3D =}
  283.  
  284. {= Circle - WCP equivalent to BGI Circle procedure =}
  285. procedure WCoordPlane.Circle( wx, wy, wRadius : Real );
  286. begin
  287.     Ellipse( wx, wy, 0, 360, wRadius, wRadius );
  288. end; {= Circle =}
  289.  
  290. {= ClearWorld - WCP equivalent to BGI ClearViewPort procedure =}
  291. procedure WCoordPlane.ClearWorld;
  292. begin
  293.     ActivateViewPort;
  294.     ClearViewPort;
  295.     LocateCurrentPtr;
  296. end; {= Clear =}
  297.  
  298. {= DrawPoly - WCP equivalent to BGI DrawPoly procedure =}
  299. procedure WCoordPlane.DrawPoly( numPoints: Word; var polyPoints );
  300. var
  301.     points : PPointArray;
  302.     i : Integer;
  303. begin
  304.     GetMem( points, numPoints * SizeOf( PointType ) );
  305.     ActivateViewPort;
  306.     for i := 1 to numPoints do
  307.     begin             { Typecast polyPoints to a RealPointArray }
  308.         Convert( RealPointArray( polyPoints )[ i ].x,
  309.                  RealPointArray( polyPoints )[ i ].y,
  310.                  points^[ i ].x,
  311.                  points^[ i ].y );
  312.     end;
  313.     Graph.DrawPoly( numPoints, points^ );
  314. end; {= DrawPoly =}
  315.  
  316. {= Ellipse - WCP equivalent to BGI Ellipse procedure =}
  317. procedure WCoordPlane.Ellipse( wx, wy : Real;
  318.                                stAngle, endAngle : Word;
  319.                                wxRadius, wyRadius : Real );
  320. var
  321.     x, y : Integer;
  322.     xRadius, yRadius : Word;
  323. begin
  324.     ActivateViewPort;
  325.     Convert( wx, wy, x, y );
  326.     ConvertRadii( wxRadius, wyRadius, xRadius, yRadius );
  327.     Graph.Ellipse( x, y, stAngle, endAngle, xRadius, yRadius );
  328. end; {= Ellipse =}
  329.  
  330. {= FillEllipse - WCP equivalent to BGI FillEllipse procedure =}
  331. procedure WCoordPlane.FillEllipse( wx, wy,
  332.                                    wxRadius, wyRadius : Real );
  333. var
  334.     x, y : Integer;
  335.     xRadius, yRadius : Word;
  336. begin
  337.     ActivateViewPort;
  338.     Convert( wx, wy, x, y );
  339.     ConvertRadii( wxRadius, wyRadius, xRadius, yRadius );
  340.     Graph.FillEllipse( x, y, xRadius, yRadius );
  341. end; {= FillEllipse =}
  342.  
  343. {= FillPoly - WCP equivalent to BGI FillPoly procedure =}
  344. procedure WCoordPlane.FillPoly( numPoints: Word; var polyPoints );
  345. var
  346.     points : PPointArray;
  347.     i : Integer;
  348. begin
  349.     GetMem( points, numPoints * SizeOf( PointType ) );
  350.     ActivateViewPort;
  351.     for i := 1 to numPoints do
  352.     begin               { Typecase polyPoints to RealPointArray }
  353.         Convert( RealPointArray( polyPoints )[ i ].x,
  354.                  RealPointArray( polyPoints )[ i ].y,
  355.                  points^[ i ].x,
  356.                  points^[ i ].y );
  357.     end;
  358.     Graph.FillPoly( numPoints, points^ );
  359. end; {= FillPoly =}
  360.  
  361. {= FloodFill - WCP equivalent to BGI FloodFill procedure =}
  362. procedure WCoordPlane.FloodFill( wx, wy : Real; border : Word );
  363. var
  364.     x, y : Integer;
  365. begin
  366.     ActivateViewPort;
  367.     Convert( wx, wy, x, y );
  368.     Graph.FloodFill( x, y, border );
  369. end; {= FloodFill =}
  370.  
  371. {= GetImage - WCP equivalent to BGI GetImage procedure =}
  372. procedure WCoordPlane.GetImage( wx1, wy1, wx2, wy2 : Real;
  373.                                 var bitMap );
  374. var
  375.     x1, y1, x2, y2 : Integer;
  376. begin
  377.     ActivateViewPort;
  378.     Convert( wx1, wy1, x1, y1 );
  379.     Convert( wx2, wy2, x2, y2 );
  380.     Graph.GetImage( x1, y1, x2, y2, bitMap );
  381. end; {= GetImage =}
  382.  
  383. {= GetPixel - WCP equivalent to BGI GetPixel function =}
  384. function WCoordPlane.GetPixel( wx, wy : Real ): Word;
  385. var
  386.     x, y : Integer;
  387. begin
  388.     ActivateViewPort;
  389.     Convert( wx, wy, x, y );
  390.     GetPixel := Graph.GetPixel( x, y );
  391. end; {= GetPixel =}
  392.  
  393. {= ImageSize - WCP equivalent to BGI ImageSize function =}
  394. function WCoordPlane.ImageSize( wx1, wy1, wx2, wy2 : Real ): Word;
  395. var
  396.     x1, y1, x2, y2 : Integer;
  397. begin
  398.     ActivateViewPort;
  399.     Convert( wx1, wy1, x1, y1 );
  400.     Convert( wx2, wy2, x2, y2 );
  401.     ImageSize := Graph.ImageSize( x1, y1, x2, y2 );
  402. end; {= ImageSize =}
  403.  
  404. {= Line - WCP equivalent to BGI Line procedure =}
  405. procedure WCoordPlane.Line( wx1, wy1, wx2, wy2 : Real );
  406. var
  407.     x1, x2, y1, y2 : Integer;
  408. begin
  409.     ActivateViewPort;
  410.     Convert( wx1, wy1, x1, y1 );
  411.     Convert( wx2, wy2, x2, y2 );
  412.     Graph.Line( x1, y1, x2, y2 );
  413. end; {= Line =}
  414.  
  415. {= LineRel - WCP equivalent to BGI LineRel procedure =}
  416. procedure WCoordPlane.LineRel( wdx, wdy : Real );
  417. var
  418.     x, y : Integer;
  419. begin
  420.     ActivateViewPort;
  421.     ConvertRel( wdx, wdy, x, y );
  422.     Graph.LineRel( x, y );
  423.     LocateCurrentPtr;
  424. end; {= LineRel =}
  425.  
  426. {= LineTo - WCP equivalent to BGI LineTo procedure =}
  427. procedure WCoordPlane.LineTo( wx, wy : Real );
  428. var
  429.     x, y : Integer;
  430. begin
  431.     ActivateViewPort;
  432.     Convert( wx, wy, x, y );
  433.     Graph.LineTo( x, y );
  434.     LocateCurrentPtr;
  435. end; {= LineTo =}
  436.  
  437. {= MoveRel - WCP equivalent to BGI MoveRel procedure =}
  438. procedure WCoordPlane.MoveRel( wdx, wdy : Real );
  439. var
  440.     x, y : Integer;
  441. begin
  442.     ActivateViewPort;
  443.     ConvertRel( wdx, wdy, x, y );
  444.     Graph.MoveRel( x, y );
  445.     LocateCurrentPtr;
  446. end; {= MoveRel =}
  447.  
  448. {= MoveTo - WCP equivalent to BGI MoveTo procedure =}
  449. procedure WCoordPlane.MoveTo( wx, wy : Real );
  450. var
  451.     x, y : Integer;
  452. begin
  453.     ActivateViewPort;
  454.     Convert( wx, wy, x, y );
  455.     Graph.MoveTo( x, y );
  456.     LocateCurrentPtr;
  457. end; {= MoveTo =}
  458.  
  459. {= OutTextXY - WCP equivalent to BGI OutTextXY procedure =}
  460. procedure WCoordPlane.OutTextXY( wx, wy : Real; message: String );
  461. var
  462.     x, y : Integer;
  463. begin
  464.     ActivateViewPort;
  465.     Convert( wx, wy, x, y );
  466.     Graph.OutTextXY( x, y, message );
  467. end; {= OutTextXY =}
  468.  
  469. {= PieSlice - WCP equivalent to BGI PieSlice procedure =}
  470. procedure WCoordPlane.PieSlice( wx, wy : Real;
  471.                                 stAngle, endAngle : Word;
  472.                                 wRadius : Real );
  473. begin
  474.     Sector( wx, wy, stAngle, endAngle, wRadius, wRadius );
  475. end;
  476.  
  477. {= PutImage - WCP equivalent to BGI PutImage procedure =}
  478. procedure WCoordPlane.PutImage( wx, wy : Real; var bitMap;
  479.                                 bitBlt : Word );
  480. var
  481.     x, y : Integer;
  482. begin
  483.     ActivateViewPort;
  484.     Convert( wx, wy, x, y );
  485.     Graph.PutImage( x, y, bitMap, bitBlt );
  486. end;
  487.  
  488. {= PutPixel - WCP equivalent to BGI PutPixel procedure =}
  489. procedure WCoordPlane.PutPixel( wx, wy : Real; color : Word );
  490. var
  491.     x, y : Integer;
  492. begin
  493.     ActivateViewPort;
  494.     Convert( wx, wy, x, y );
  495.     Graph.PutPixel( x, y, color );
  496. end; {= PutPixel =}
  497.  
  498. {= Rectangle - WCP equivalent to BGI Rectangle procedure =}
  499. procedure WCoordPlane.Rectangle( wx1, wy1, wx2, wy2 : Real );
  500. var
  501.     x1, x2, y1, y2 : Integer;
  502. begin
  503.     ActivateViewPort;
  504.     Convert( wx1, wy1, x1, y1 );
  505.     Convert( wx2, wy2, x2, y2 );
  506.     Graph.Rectangle( x1, y1, x2, y2 );
  507. end; {= Rectangle =}
  508.  
  509. {= Sector - WCP equivalent to BGI Sector procedure =}
  510. procedure WCoordPlane.Sector( wx, wy : Real;
  511.                               stAngle, endAngle : Word;
  512.                               wxRadius, wyRadius : Real );
  513. var
  514.     x, y : Integer;
  515.     xRadius, yRadius : Word;
  516. begin
  517.     ActivateViewPort;
  518.     Convert( wx, wy, x, y );
  519.     ConvertRadii( wxRadius, wyRadius, xRadius, yRadius );
  520.     Graph.Sector( x, y, stAngle, endAngle, xRadius, yRadius );
  521. end; { WSector }
  522.  
  523. {= SetColor - WCP equivalent to BGI SetColor procedure =}
  524. procedure WCoordPlane.SetColor( color : Word );
  525. begin
  526.     Graph.SetColor( color );
  527.     currentColor := color;
  528. end;
  529.  
  530. {= SetFillPattern - WCP equivalent to BGI SetFillPattern procedure=}
  531. procedure WCoordPlane.SetFillPattern( pattern : FillPatternType;
  532.                                       color : Word );
  533. begin
  534.     Graph.SetFillPattern( pattern, color );
  535.     fillPattern := pattern;
  536.     fillSettings.color := color;
  537. end; {= SetFillPattern =}
  538.  
  539. {= SetFillStyle - WCP equivalent to BGI SetFillStyle procedure =}
  540. procedure WCoordPlane.SetFillStyle( pattern : Word; color: Word );
  541. begin
  542.     Graph.SetFillStyle( pattern, color );
  543.     fillSettings.pattern := pattern;
  544.     fillSettings.color := color;
  545. end; {= SetFillStyle =}
  546.  
  547. {= SetLineStyle - WCP equivalent to BGI SetLineStyle procedure =}
  548. procedure WCoordPlane.SetLineStyle( lineStyle, pattern,
  549.                                     thickness : Word );
  550. begin
  551.     Graph.SetLineStyle( lineStyle, pattern, thickness );
  552.     lineSettings.lineStyle := lineStyle;
  553.     lineSettings.pattern := pattern;
  554.     lineSettings.thickness := thickness;
  555. end; {= SetLineStyle =}
  556.  
  557. {= SetTextJustify - WCP equivalent to BGI SetTextJustify procedure=}
  558. procedure WCoordPlane.SetTextJustify( horiz, vert : Word );
  559. begin
  560.     Graph.SetTextJustify( horiz, vert );
  561.     textSettings.horiz := horiz;
  562.     textSettings.vert := vert;
  563. end; {= SetTextJustify =}
  564.  
  565. {= SetTextStyle - WCP equivalent to BGI SetTextStyle procedure =}
  566. procedure WCoordPlane.SetTextStyle( font, direction,
  567.                                     charSize : Word );
  568. begin
  569.     Graph.SetTextStyle( font, direction, charSize );
  570.     textSettings.font := font;
  571.     textSettings.direction := direction;
  572.     textSettings.charSize := charSize;
  573. end; {= SetTextStyle =}
  574.  
  575. {= SetWriteMode - WCP equivalent to BGI SetWriteMode procedure =}
  576. procedure WCoordPlane.SetWriteMode( mode : Integer );
  577. begin
  578.     Graph.SetWriteMode( mode );
  579.     writeMode := mode;
  580. end; {= SetWriteMode =}
  581.  
  582.  
  583. {= Axes - Draws a Set of Coordinate Axes in a WCP. See article =}
  584. {=        for a description of parameters.                     =}
  585. procedure WCoordPlane.Axes( wxOrigin,wyOrigin,xDelta,yDelta: Real;
  586.                             xAxis, yAxis, precision : Integer;
  587.                             arrows : Boolean;
  588.                             color : Word );
  589. var
  590.     xOrigin, yOrigin, x, y, center : Integer;
  591.     xi, yi : Real;            { Indexes for tick mark locations }
  592.     xStr, yStr : String;                     { Temp string vars }
  593.     oldTextSettings : TextSettingsType;
  594.     oldColor : Word;
  595.     oldLineSettings : LineSettingsType;
  596.  
  597. { DrawXTick - Draws tick mark on x axis }
  598. procedure DrawXTick( xi : Real );
  599. begin
  600.     Convert( xi, 0, x, y );
  601.     if ( Abs( x - xOrigin ) > 10 ) or ( yAxis < 0 ) then
  602.     begin                 { Display tick mark and label }
  603.         Graph.Line( x, yOrigin + 3, x, yOrigin - 3 );
  604.         Str( xi:1:precision, xStr );
  605.         Graph.OutTextXY( x, yOrigin + 6, xStr );
  606.     end;
  607. end;
  608.  
  609. { DrawYTick - Draws tick mark on y axis }
  610. procedure DrawYTick( yi : Real );
  611. begin
  612.     Convert( 0, yi, x, y );
  613.     if ( Abs( y - yOrigin ) > 10 ) or ( xAxis < 0 ) then
  614.     begin                 { Display tick mark and label }
  615.         Graph.Line( xOrigin - 4, y, xOrigin + 4, y );
  616.         Str( yi:1:precision, yStr );
  617.         center := ( Length( yStr ) * 8 ) div 2;
  618.         Graph.OutTextXY( xOrigin - center - 5, y, yStr );
  619.     end;
  620. end;
  621.  
  622. begin {= Axes =}
  623.     ActivateViewPort;
  624.     Convert( wxOrigin, wyOrigin, xOrigin, yOrigin );
  625.     oldColor := GetColor;
  626.     SetColor( color );
  627.     Graph.GetLineSettings( oldLineSettings );
  628.     if xAxis >= 0 then
  629.     begin                             { If visible, draw x-axis }
  630.         SetLineStyle( Abs( xAxis ), 0, NormWidth );
  631.         Graph.Line( 0, yOrigin, vpMaxX, yOrigin );
  632.     end;
  633.  
  634.     if yAxis >= 0 then
  635.     begin                             { If visible, draw y-axis }
  636.         SetLineStyle( Abs( yAxis ), 0, NormWidth );
  637.         Graph.Line( xOrigin, 0, xOrigin, vpMaxY );
  638.     end;
  639.  
  640.     if ( ( xDelta < 0 ) and ( yDelta > 0 ) ) or
  641.        ( ( xDelta > 0 ) and ( yDelta < 0 ) ) then
  642.     begin                    { If opposite signs, draw a border }
  643.         xDelta := Abs( xDelta );
  644.         yDelta := Abs( yDelta );
  645.         Graph.Rectangle( 0, 0, vpMaxX, vpMaxY );
  646.     end;
  647.  
  648.     if arrows then
  649.     begin                       { Draw arrows on ends of axes.. }
  650.         if yAxis >= 0 then
  651.         begin                     { But only if axis is visible }
  652.                                               { Top YAxis arrow }
  653.             Graph.Line( xOrigin + 4, 4, xOrigin, 0 );
  654.             Graph.Line( xOrigin, 0, xOrigin - 4, 4 );
  655.                                            { Bottom YAxis arrow }
  656.             Graph.Line( xOrigin + 4, vpMaxY - 4, xOrigin, vpMaxY );
  657.             Graph.Line( xOrigin, vpMaxY, xOrigin - 4, vpMaxY - 4 );
  658.         end;
  659.         
  660.         if xAxis >= 0 then
  661.         begin                     { But only if axis is visible }
  662.                                              { Left XAxis arrow }
  663.             Graph.Line( 4, yOrigin + 4, 0, yOrigin );
  664.             Graph.Line( 0, yOrigin, 4, yOrigin - 4 );
  665.                                             { Right XAxis arrow }
  666.             Graph.Line( vpMaxX - 4, yOrigin + 4, vpMaxX, yOrigin );
  667.             Graph.Line( vpMaxX, yOrigin, vpMaxX - 4, yOrigin - 4 );
  668.         end;
  669.     end;
  670.     GetTextSettings( oldTextSettings );
  671.     SetTextStyle( SMALLFONT, HORIZDIR, 4 );
  672.     SetTextJustify( CENTERTEXT, CENTERTEXT );
  673.  
  674.     if xAxis >= 0 then
  675.     begin                       { Display ticks if axis visible }
  676.         xi := wxOrigin + xDelta;              { Start at Origin }
  677.         while Abs( wxLR ) - Abs( xi ) > 0.000001 do
  678.         begin                        { While still have room... }
  679.             DrawXTick( xi );               { Draw the tick mark }
  680.             xi := xi + xDelta;           { Go to next tick mark }
  681.         end;
  682.                                          { Other side of x axis }
  683.         xi := wxOrigin - xDelta;               { Back to Origin }
  684.         while Abs( wxUL ) - Abs( xi ) > 0.000001 do
  685.         begin                        { While still have room... }
  686.             DrawXTick( xi );               { Draw the tick mark }
  687.             xi := xi - xDelta;           { Go to next tick mark }
  688.         end;
  689.     end; { if xAxis }
  690.  
  691.     if yAxis >= 0 then
  692.     begin                       { Display ticks if axis visible }
  693.         yi := wyOrigin + yDelta;              { Start at Origin }
  694.         while Abs( wyLR ) - Abs( yi ) > 0.000001 do
  695.         begin                        { While still have room... }
  696.             DrawYTick( yi );               { Draw the tick mark }
  697.             yi := yi + yDelta;           { Go to next tick mark }
  698.         end;
  699.                                          { Other side of y axis }
  700.         yi := wyOrigin - yDelta;               { Back to Origin }
  701.         while Abs( wyLR ) - Abs( yi ) > 0.000001 do
  702.         begin                        { While still have room... }
  703.             DrawYTick( yi );               { Draw the tick mark }
  704.             yi := yi - yDelta;           { Go to next tick mark }
  705.         end;
  706.     end; { if yAxis }
  707.  
  708.     with oldTextSettings do              { Restore old settings }
  709.     begin
  710.         SetTextStyle( Font, Direction, CharSize );
  711.         SetTextJustify( Horiz, Vert );
  712.     end;
  713.     with oldLineSettings do
  714.         SetLineStyle( lineStyle, pattern, thickness );
  715.     SetColor( oldColor );
  716. end; {= Axes =}
  717.  
  718. end. {=== GraphWld Unit ===}
  719.  
  720.